/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package character_9;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Objects;

/**
 *
 * @author Administrator
 */
public class Stack {
    
    private Deque elems = new ArrayDeque();
    private int capacity;

    public Stack(int capacity) {
        this.capacity = capacity;
    }
    
    public boolean push(Object elem){
        if (isFull()) {
            return false;
        }
        return elems.offerLast(elem);
    }
    
    private boolean isFull(){
        return elems.size() + 1 > capacity;
    }
    
    public Object pop(){
        return elems.pollLast();
    }
    
    public Object peek(){
        return elems.peekLast();
    }
    
    public int size(){
        return elems.size();
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 79 * hash + Objects.hashCode(this.elems);
        hash = 79 * hash + this.capacity;
        return hash;
    }
    
}
